import siwin, shady
import gl

var window = newOpenglWindow(title="lopengl")
loadExtensions()


proc shaderVert(
  gl_Position: var Vec4,
  pos: Vec2,
) =
  gl_Position = vec4(pos, vec2(0, 1))

proc shaderFrag(
  glCol: var Vec4,
  col: Uniform[Vec4],
) =
  glCol = col

let solidShader = newShader {GlVertexShader: shaderVert.toGlsl, GlFragmentShader: shaderFrag.toGlsl}


let rect = newShape(
  [
    vec2(-1, 1),  # top left
    vec2(-1, -1), # bottom left
    vec2(1, -1),  # bottom right
    vec2(1, 1),   # top right
  ],
  [
    0'u32, 1, 2,
    2, 3, 0,
  ]
)

window.onResize = proc(e: ResizeEvent) =
  glViewport 0, 0, e.size.x.GLsizei, e.size.y.GLsizei

window.onRender = proc(e: RenderEvent) =
  glClearColor 0.3, 0.3, 0.3, 1
  glClear GlColorBufferBit or GlDepthBufferBit

  use solidShader
  solidShader["col"] = vec4(1.0, 0.5, 0.2, 1.0)
  draw rect

  redraw window

run window
